package config;

import dubbo.ConsumerComponent;
import dubbo.filter.MethodInvokerInfo;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description: TODO
 * @Author 50705 2021/11/23
 **/
public class AnnotationConsumerMain {

    public Map<String, List<MethodInvokerInfo>> methodMap = new ConcurrentHashMap<>();

    public static Object lock = new Object();

    static ConsumerComponent service;

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        service = context.getBean(ConsumerComponent.class);

//        String result = service.methodA("methodA");
//        String result1 = service.methodB("methodB");
//        String result2 = service.methodC("methodC");
//        System.out.println("result :" + result);
//        System.out.println("result :" + result1);
//        System.out.println("result :" + result2);

//        DubboInvokeFilter dubboInvokeFilter = new DubboInvokeFilter();
//        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(dubboInvokeFilter, 5, 5 , TimeUnit.SECONDS);

        while (true) {
            for(int i=0;i<50;i++){
                AsyncTaskExecutor.getInstance().execute(service);
            }
            Thread.sleep(500);
        }
    }


    @Configuration
    @EnableDubbo
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(value = {"dubbo"})
    static class ConsumerConfiguration {


    }
}
